﻿using BBICMS.Model;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BBICMS.Repository.Configuration
{
    public class PostConfiguration : EntityTypeConfiguration<Post>
    {
        public PostConfiguration()
        {
            this.HasKey(p => p.Id);

            this.Property(p => p.Id)
                .HasColumnName("PostId")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.ToTable("Posts");

            this.Property(p => p.Title).HasMaxLength(100).IsRequired();  
            this.Property(p => p.BlogId).IsRequired();
            this.Property(p => p.ViewCount).IsRequired();
            this.Property(p => p.AddedDate).IsRequired().HasColumnType("datetime");
            this.Property(p => p.AddedBy).HasMaxLength(50);
            this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);
            this.Property(p => p.Pubdate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.Author).HasMaxLength(50);

            this.HasRequired(p => p.Blog)
            .WithMany(h=>h.Posts)
            .HasForeignKey(p => p.BlogId);  
        }
    }
}
